Skip to content

agent: @U0AJM7X8FBR Chat - /files page - Drag-n-Drop Files.#333

Open
sweetmantech wants to merge 1 commit intotestfrom
feature/sandbox-file-upload
Open

agent: @U0AJM7X8FBR Chat - /files page - Drag-n-Drop Files.#333
sweetmantech wants to merge 1 commit intotestfrom
feature/sandbox-file-upload

Conversation

@sweetmantech
Copy link
Copy Markdown
Contributor

Automated PR from coding agent.

Prompt: @U0AJM7X8FBR Chat - /files page - Drag-n-Drop Files.
• actual: I am unable to drag and drop files on the /files page to add them to my github repository in an org submodule.
• required: I can drag and drop files on the /files page to add them to my github repository in an org submodule.

…org submodules

- lib/github/commitFileToRepo.ts: GitHub Contents API utility to create/update files in a repo
- lib/sandbox/uploadSandboxFilesHandler.ts: multipart handler that resolves submodule paths and commits files
- lib/sandbox/__tests__/uploadSandboxFilesHandler.test.ts: 6 passing tests (TDD)
- app/api/sandboxes/files/route.ts: POST route wired to handler

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 23, 2026

Warning

Rate limit exceeded

@sweetmantech has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 15 minutes and 49 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4bd220cf-890a-4588-aac1-5534d274c724

📥 Commits

Reviewing files that changed from the base of the PR and between 4b895cc and d824993.

⛔ Files ignored due to path filters (1)
  • lib/sandbox/__tests__/uploadSandboxFilesHandler.test.ts is excluded by !**/*.test.*, !**/__tests__/** and included by lib/**
📒 Files selected for processing (3)
  • app/api/sandboxes/files/route.ts
  • lib/github/commitFileToRepo.ts
  • lib/sandbox/uploadSandboxFilesHandler.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/sandbox-file-upload

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
recoup-api Ready Ready Preview Mar 23, 2026 5:54pm

Request Review

Copy link
Copy Markdown
Collaborator

@recoup-coding-agent recoup-coding-agent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review: Chat - /files page - Drag-n-Drop Files

Summary

Adds POST /api/sandboxes/files endpoint to upload files from the drag-and-drop UI to the authenticated account's GitHub org submodule. Files are resolved through resolveSubmodulePath so they land in the correct sub-repo. Good test coverage across auth, validation, snapshot lookup, and upload result cases.


CLEAN Code Assessment

SRP ✅ commitFileToRepo handles GitHub, uploadSandboxFilesHandler handles orchestration — well separated.

OCP ✅ No modification to existing code paths.

DRY ✅ Reuses validateAuthContext, selectAccountSnapshots, resolveSubmodulePath.

YAGNI ✅ No over-engineering; handles exactly what was asked.


Issues Found

🔴 Blocking

1. Path traversal via file.name

const fullPath = `${folder.replace(/\/$/, "")}/${file.name}`;

file.name comes from the Content-Disposition header in the multipart body and is not sanitized. A crafted request could send file.name = "../../../.env", resulting in a path like .openclaw/workspace/orgs/myorg/../../../.env, which GitHub normalizes to .env at the repo root — allowing arbitrary file writes.

Fix: strip ../ sequences and leading slashes from file.name before building the path:

const safeName = file.name.replace(/(\.\.\/|\.\.\\/|^\/)/g, "").replace(/[\x00-\x1f]/g, "");
const fullPath = `${folder.replace(/\/$/, "")}/${safeName}`;

🟡 Suggestions

2. Hardcoded branch: "main" in commitFileToRepo

branch: "main",

This silently targets main regardless of the actual default branch. Repos using master or another default branch will fail. Consider either:

  • Accepting branch as an optional parameter (defaulting to "main"), or
  • Fetching the repo's default branch via GET /repos/{owner}/{repo} when not provided.

3. Unhandled selectAccountSnapshots rejection

The snapshots lookup isn't wrapped in try/catch. A database error will produce an unhandled 500. Given the pattern used in similar handlers, wrap in try/catch with a { status: 500 } response.

4. No file size limit

The handler accepts arbitrarily large files. Consider adding a limit (e.g., 10MB per file or per request) before calling file.arrayBuffer() to avoid memory exhaustion.


🔵 Nits

  • Empty JSDoc blocks on createMockFormData and createMockRequest test helpers — remove them.

Security

🔴 Path traversal via file.name (see blocking issue above).
✅ Auth enforced via validateAuthContext.
✅ No hardcoded secrets.

Verdict: request-changes

Path traversal on file.name must be fixed before merging. The branch hardcoding and missing try/catch are worth addressing in the same PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants